home *** CD-ROM | disk | FTP | other *** search
- Path: hpscit.sc.hp.com!news
- From: "N. Srinivasan" <ns@india.hp.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Operator overloading
- Date: Wed, 13 Mar 1996 18:19:32 +0500
- Organization: Hewlett-Packard Company
- Message-ID: <3146CB64.545C@india.hp.com>
- References: <313F19B5.41C6@lfa.uni-wuppertal.de> <314575D9.3A2A@teambca.com>
- NNTP-Posting-Host: victory.india.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; HP-UX A.09.05 9000/712)
-
- Mark VanTassel wrote:
- >
- > > const T& operator[](unsigned long int index) const;
- > >
- > > I know, it is an subscription overloading, for something like
- > > v[i], where i is of type unsigned long int and v of type T.
- > >
- > > What's the meaning of the const at the end
- > > and the beginning of the line ?
- > >
- >
- > The const at the end says that this member function (it must be a member, since it only defines
- > one argument) cannot modify the state of the object to which it is being applied (the
- > pseudo-array which is being "indexed").
- >
- > The const at the beginning says that the object (of type T) to which a reference is returned
- > cannot be modified by the caller of this "index" operation.
- >
- > (Note that both can be overridden by casting the constness away. This should NEVER be done,
- > except in certain circumstances ;-)
- The const at the end makes the function a "const function".
- This means that it can be called for a const instance of the class in which it is
- defined.
- Functions which are not "const" cannot be called for const instances.
- --
- Regards,
- ns(N. Srinivasan)
- ------------------
- "Unix was not designed to stop you from doing stupid things, because
- that would also stop you from doing clever things" -- Doug Gwyn
-